home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / compuserve-file-archive / 05 Programming / VIOLIN.C < prev    next >
Text File  |  2019-04-13  |  12KB  |  428 lines

  1.  #include"stdio.h"
  2.  #include"graphic.h"
  3.  #include"math.h"
  4.  #include"sound.h"
  5.  #include"scale.h"
  6.  
  7.  #define MAXNOTE  16
  8.  #define FRET    150
  9.  #define ROW      16
  10.  #define COLUMN    2
  11.  #define DIST     15
  12.  #define XSTAFF   40
  13.  #define YSTAFF  160
  14.  
  15.  int    notenum;
  16.  int    choice[5];
  17.  int    x, y, z, k;
  18.  char   c;
  19.  int    staff[MAXNOTE];
  20.  
  21.  
  22.  int    fingers[ROW][COLUMN] =    23, 150 ,   /* g */
  23.                                    23, 120 ,   /* a */
  24.                                    23,  90 ,   /* b */
  25.                                    23,  76 ,   /* c */
  26.                                    26, 150 ,   /* d */
  27.                                    26, 120 ,   /* e */
  28.                                    26,  104 ,  /* f */
  29.                                    26,  76 ,   /* g */
  30.                                    29, 150 ,   /* a */
  31.                                    29, 120 ,   /* b */
  32.                                    29,  104 ,  /* c */
  33.                                    29,   76 ,  /* d */
  34.                                    32, 150 ,   /* e */
  35.                                    32, 134 ,   /* f */
  36.                                    32,  104 ,  /* g */
  37.                                    32,  76  ; /* a */
  38.  
  39.  
  40.  
  41.  
  42.  main()
  43.  
  44.  void   inst();
  45.  void   board();
  46.  void   scheme();
  47.  void   strings();
  48.  void   draw_staff();
  49.  void   display();
  50.  void   play();
  51.  void   show();
  52.  void   put_note();
  53.  void   point();
  54.  
  55.  inst();
  56.  
  57.  getchar();
  58.  
  59.  /*     SETUPGRAFIX   */
  60.  
  61.  graphic();
  62.  graphon();
  63.  backgr(14,1);
  64.  clrmap(0);
  65.  colors(0, 13, 4);
  66.  
  67.  board(); strings(); scheme(); draw_staff();
  68.  
  69.  voice1.lh_pulse=159;               /*  lower half of pulse width value        */
  70.  voice1.uh_pulse=31;                /*  upper half of pulse width value        */
  71.  voice1.waveform=33;                /*  waveform control register              */
  72.  voice1.atck_dcay=9;                /*  attack and decay control register      */
  73.  voice1.sus_rel=224;                /*  sustain and release control register   */
  74.  
  75.  voice2.lh_pulse=159;               /*  lower half of pulse width value        */
  76.  voice2.uh_pulse=31;                /*  upper half of pulse width value        */
  77.  voice2.waveform=277;               /*  waveform control register              */
  78.  voice2.atck_dcay=9;                /*  attack and decay control register      */
  79.  voice2.sus_rel=224;                /*  sustain and release control register   */
  80.  
  81.  voice3.lh_pulse=225;               /*  lower half of pulse width value        */
  82.  voice3.uh_pulse=0;                 /*  upper half of pulse width value        */
  83.  voice3.waveform=65;                /*  waveform control register              */
  84.  voice3.atck_dcay=9;                /*  attack and decay control register      */
  85.  voice3.sus_rel=20;                 /*  sustain and release control register   */
  86.  
  87.  voice2.lh_tone=0;
  88.  voice2.uh_tone=0;
  89.  
  90.  voice3.lh_tone=0;
  91.  voice3.uh_tone=0;
  92.  
  93.  filter.lh_cutoff=11;                   /*  lower half of cut-off filter       */
  94.  filter.uh_cutoff=33;                   /*  upper half of cut-off filter       */
  95.  filter.res_sound=154;                  /*  resonance and sound filtering      */
  96.  filter.mode_vol=0;                     /*  mode and volume controls           */
  97.  
  98.  notenum=1;
  99.  
  100.  while((c=getchar())!='x')
  101.  
  102.     if((c=getchar())=='d')display();
  103.  
  104.     if((c=getchar())=='p')play();
  105.  
  106.     if((c=getchar())=='s')show();
  107.  
  108.     if((c=getchar())=='+') notenum++; if(notenum>3) notenum=4; 
  109.     if((c=getchar())=='-') notenum--; if(notenum<2) notenum=1; 
  110.  
  111.     if((c=getchar())=='c')
  112.        printf("%c", CLR);
  113.        clrmap(0);
  114.        board(); strings(); scheme();  draw_staff();
  115.        
  116.  
  117.    /*  end while()  */
  118.  
  119.    /*  end main    ************************************************************/
  120.  
  121.  
  122.  /*     DISPLYLISTOFCOMMANDS     ********************************************/
  123.  void   inst()
  124.  
  125.  printf("%c",'\037');
  126.  printf("%c%c  Write down these commands; character\n", CLR, HOME );
  127.  printf("mode will be disabled during GrAfIx MoDe\n\n\n");
  128.  printf("d: Display notes on the staff.\n");
  129.  printf("p: Play the tones indicated\n   on the staff.\n");
  130.  printf("s: Show the location of the notes\n   on the ");
  131.  printf("violin finger board.\n");
  132.  printf("c: Clear screen\n");
  133.  printf("+: Increases number of notes, up to 4.\n");
  134.  printf("-: Decreases number of notes.\n");
  135.  printf("x: EXIT from the program.\n");
  136.  printf("\n Commands can be repeated. \n");
  137.  printf("\n Please e-mail responses to James Britt\n");
  138.  printf(" on CompuServe:  73417,2776.\n");
  139.  printf("\n        HAVEFUN!\n ENTERANYTHINGTOGETSTARTED!\n\n");
  140.  
  141.  return;
  142.  
  143.    /*  end inst()  ************************************************************/
  144.  
  145.  /*     DRAWFINGERBOARD      **************************************************/
  146.  
  147.  void board()
  148.  
  149.  
  150.  setcol(2);
  151.  shape(21, FRET, 34, 20);
  152.  /*
  153.  setcol(3);
  154.  
  155.  shape(21,FRET,34,FRET-DIST+1);
  156.  shape(21,FRET-(2*DIST),34,FRET-(3*DIST-1));
  157.  shape(21,FRET-(4*DIST),34,FRET-(5*DIST-1));
  158.  shape(21,FRET-(6*DIST),34,FRET-(7*DIST-1));
  159.    */
  160.  return;
  161.  
  162.    /*  end board()    *********************************************************/
  163.  
  164.  
  165.  /*     DRAWSTRINGS       *****************************************************/
  166.  
  167.  void strings()
  168.  
  169.  
  170.  setcol(1);
  171.  line(23,-2,23,150);
  172.  line(26,-2,26,150);
  173.  line(29,-2,29,150);
  174.  line(32,-2,32,150);
  175.  
  176.  return;
  177.  
  178.    /*  end strings()   ********************************************************/
  179.  
  180.  /*     SHOWFINGERINGSCHEMEONBOARD              ****************************/
  181.  void scheme()
  182.  
  183.  int    x, y, r;
  184.  setcol(0);
  185.  
  186.     for(r=0; r<ROW+1; r++)
  187.  
  188.     x=fingers[r][0];
  189.     y=fingers[r][1];
  190.  
  191.     dot(x, y+2); dot(x-1, y+1);
  192.     dot(x-1, y); dot(x-1, y-1);
  193.     dot(x, y-2); dot(x+1, y-1);
  194.     dot(x+1, y); dot(x+1, y+1);
  195.     
  196.  return;
  197.  
  198.    /*  end scheme()  **********************************************************/
  199.  
  200.  /*      DRAWSTAFF         ****************************************************/
  201.  
  202.  
  203.  void draw_staff()
  204.  
  205.  setcol(1);
  206.  for(k=0; k<5; k++ )
  207.     setplot(XSTAFF, YSTAFF + k*6 );
  208.     plot(150, YSTAFF + k*6 );
  209.     
  210.  
  211.  line(XSTAFF, YSTAFF, XSTAFF, YSTAFF + 24 );
  212.  line(150, YSTAFF, 150, YSTAFF + 24 );
  213.  /* line((XSTAFF+150)/2,  YSTAFF, (XSTAFF+150)/2 , YSTAFF + 24 );  */
  214.  
  215.  return;
  216.  
  217.   /*   end draw_staff()      **********************************/
  218.  
  219.  
  220.  /*     DISPLAYNOTESONTHESTAFF  ********************************************/
  221.  void   display()
  222.  
  223.  int    k;
  224.  int    dist;
  225.  
  226.  dist = (150-XSTAFF)/5;
  227.  
  228.  for(k=0; k<notenum; k++)
  229.     choice[k]  = (((int)(rnd(0)*2196))%MAXNOTE)    ;
  230.     put_note( XSTAFF+dist*(1+k), (YSTAFF-15)+3*choice[k] );
  231.     
  232.  return;
  233.  
  234.    /*  end display()   ********************************************************/
  235.  
  236.  /*     PLAYNOTESSHOWNONSTAFF   ********************************************/
  237.  
  238.  void   play()
  239.  
  240.  
  241.  int    q, x;
  242.  int    dist;
  243.  
  244.  dist = (150-XSTAFF)/5;
  245.  
  246.  for(x=0; x<notenum; x++)
  247.  
  248.     filter.mode_vol = 0;
  249.  
  250.     switch(choice[x])
  251.  
  252.         case  0 :    voice1.lh_tone = note[_G_ oct4][lower];
  253.                      voice1.uh_tone = note[_G_ oct4][upper];
  254.                      break;
  255.  
  256.         case  1 :    voice1.lh_tone = note[_A_ oct4][lower];
  257.                      voice1.uh_tone = note[_A_ oct4][upper];
  258.                      break;
  259.  
  260.         case  2 :    voice1.lh_tone = note[_B_ oct4][lower];
  261.                      voice1.uh_tone = note[_B_ oct4][upper];
  262.                      break;
  263.  
  264.         case  3 :    voice1.lh_tone = note[_C_ oct5][lower];
  265.                      voice1.uh_tone = note[_C_ oct5][upper];
  266.                      break;
  267.  
  268.         case  4 :    voice1.lh_tone = note[_D_ oct5][lower];
  269.                      voice1.uh_tone = note[_D_ oct5][upper];
  270.                      break;
  271.  
  272.         case  5 :    voice1.lh_tone = note[_E_  oct5][lower];
  273.                      voice1.uh_tone = note[_E_  oct5][upper];
  274.                      break;
  275.  
  276.         case  6 :    voice1.lh_tone = note[_F_ oct5][lower];
  277.                      voice1.uh_tone = note[_F_ oct5][upper];
  278.                      break;
  279.  
  280.         case  7 :    voice1.lh_tone = note[_G_ oct5][lower];
  281.                      voice1.uh_tone = note[_G_ oct5][upper];
  282.                      break;
  283.  
  284.         case  8 :    voice1.lh_tone = note[_A_ oct5][lower];
  285.                      voice1.uh_tone = note[_A_ oct5][upper];
  286.                      break;
  287.  
  288.         case  9 :    voice1.lh_tone = note[_B_ oct5][lower];
  289.                      voice1.uh_tone = note[_B_ oct5][upper];
  290.                      break;
  291.  
  292.         case 10 :    voice1.lh_tone = note[_C_ oct6][lower];
  293.                      voice1.uh_tone = note[_C_ oct6][upper];
  294.                      break;
  295.  
  296.         case 11 :    voice1.lh_tone = note[_D_ oct6][lower];
  297.                      voice1.uh_tone = note[_D_ oct6][upper];
  298.                      break;
  299.  
  300.         case 12 :    voice1.lh_tone = note[_E_ oct6][lower];
  301.                      voice1.uh_tone = note[_E_ oct6][upper];
  302.                      break;
  303.  
  304.         case 13 :    voice1.lh_tone = note[_F_ oct6][lower];
  305.                      voice1.uh_tone = note[_F_ oct6][upper];
  306.                      break;
  307.  
  308.         case 14 :    voice1.lh_tone = note[_G_ oct6][lower];
  309.                      voice1.uh_tone = note[_G_ oct6][upper];
  310.                      break;
  311.  
  312.         case 15 :    voice1.lh_tone = note[_A_ oct6][lower];
  313.                      voice1.uh_tone = note[_A_ oct6][upper];
  314.                      break;
  315.  
  316.         default :    break;
  317.  
  318.            /* end switch  */
  319.  
  320.     voice2.lh_tone = voice1.lh_tone;
  321.     voice2.uh_tone = voice1.uh_tone;
  322.  
  323.     voice3.lh_tone = voice1.lh_tone;
  324.     voice3.uh_tone = voice1.uh_tone;
  325.  
  326.     filter.mode_vol=15;
  327.  
  328.     setcol(0);
  329.     put_note( XSTAFF+dist*(1+x), (YSTAFF-15)+3*choice[x] );
  330.     setcol(1);
  331.  
  332.     point(x);
  333.  
  334.     for(q=0; q<1000; q++);
  335.  
  336.     filter.mode_vol=0;
  337.     setcol(1);
  338.     put_note( XSTAFF+dist*(1+x), (YSTAFF-15)+3*choice[x] );
  339.     setcol(0);
  340.     point(x);
  341.  
  342.      /* end for(choice[] )   */
  343.  
  344.  
  345.  return;
  346.  
  347.    /*  end play    ************************************************************/
  348.  
  349.  
  350.  /*     SHOWLOCATIONOFNOTESONFINGERBOARD      ****************************/
  351.  void   show()
  352.  
  353.  
  354.  
  355.  int    x, y, n;
  356.  setcol(3);
  357.  
  358.  for(n=0;n<notenum;n++)
  359.  
  360.     x=fingers[choice[n]][0];
  361.     y=fingers[choice[n]][1];
  362.  
  363.     dot(x, y+2); dot(x-1, y+1);
  364.     dot(x-1, y); dot(x-1, y-1);
  365.     dot(x, y-2); dot(x+1, y-1);
  366.     dot(x+1, y); dot(x+1, y+1);
  367.     
  368.  
  369.  return;
  370.  
  371.    /*  end show    ************************************************************/
  372.  
  373.  /*     POINTTOFINGERBOARDLOCATION      ************************************/
  374.  
  375.  void point(n)
  376.  int    n;
  377.  
  378.  int    x, y;
  379.  
  380.     x=fingers[choice[n]][0];
  381.     y=fingers[choice[n]][1];
  382.  
  383.     dot(x, y+2); dot(x-1, y+1);
  384.     dot(x-1, y); dot(x-1, y-1);
  385.     dot(x, y-2); dot(x+1, y-1);
  386.     dot(x+1, y); dot(x+1, y+1);
  387.     return;
  388.           /* end point()   ****************************************************/
  389.  
  390.  
  391.  
  392.  /*      PUTNOTESYMBOLATLOCATIONX/YONSTAFF   ****************************/
  393.  void   put_note(x, y)
  394.  
  395.  int    x, y;
  396.  
  397.  
  398.  int    n, num;
  399.  
  400.     dot(x, y+2); dot(x-1, y+1);
  401.     dot(x-1, y); dot(x-1, y-1);
  402.     dot(x, y-2); dot(x+1, y-1);
  403.     dot(x+1, y); dot(x+1, y+1);
  404.  
  405.  if(y<YSTAFF-1)
  406.  
  407.     switch(YSTAFF-y)
  408.  
  409.         case 6:  num = 2; break;
  410.         case 9:  num = 2; break;
  411.         case 12: num = 3; break;
  412.         case 15: num = 3; break;
  413.         case 18: num = 4; break;
  414.         
  415.  
  416.     for(n = 1; n<num; n++)
  417.         line(x-3, YSTAFF-6*n, x+3, YSTAFF-6*n);
  418.     
  419.  if(y>YSTAFF+27)
  420.         line(x-3, YSTAFF+30, x+3, YSTAFF+30 );
  421.  
  422.  
  423.  return;
  424.  
  425.  
  426.  
  427.  /******************************************************************************/
  428.